use std::f32::consts::PI;

use ggez::mint::Point2;
use rand::Rng;
use rand_distr::{Distribution, Normal};

pub struct Walker {
    location: Point2<f32>
}

impl Walker {
    pub fn new(location: Point2<f32>) -> Walker{
        Walker{location : location}
    }
    pub fn get_location(& self) -> Point2<f32> {
        self.location
    }
    pub fn move_to(&mut self, target: Point2<f32>) {
        let direction_x = target.x-self.location.x;
        let direction_y = target.y-self.location.y;
        let norm_x = direction_x/(direction_x*direction_x + direction_y*direction_y).sqrt();
        let norm_y = direction_y/(direction_x*direction_x + direction_y*direction_y).sqrt();
        let mut rnd = rand::thread_rng();
        let normal = Normal::new(3.0, 1.0).unwrap();
        let v = normal.sample(&mut rnd);
        self.location.x += norm_x*v;
        self.location.y += norm_y*v;
    }
    pub fn move_random(&mut self) {
        let mut rng = rand::thread_rng();
        
        let fi: f32 = 2.0*PI*(rng.gen::<f32>());
        let mut rnd = rand::thread_rng();
        let normal = Normal::new(3.0, 1.0).unwrap();
        let v = normal.sample(&mut rnd);
        self.location.x += fi.cos()*v;
        self.location.y += fi.sin()*v;
    }
}